﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _4_FindMedianSortedArrays
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] nums1 = new int[] { 1, 1 };
            int[] nums2 = new int[] { 1, 2 };
            
            double result = FindMedianSortedArrays(nums1, nums2);

            Console.Write(result);
            Console.ReadLine();

        }

        public static double FindMedianSortedArrays(int[] nums1, int[] nums2)
        {
            List<int> list = nums1.Concat<int>(nums2).OrderBy(o => o).ToList();

            if (list.Count == 0)
            {
                return 0;
            }

            int length = list.Count;

            int mid = list.Count / 2;

            if (list.Count % 2 == 1)
            {
                int v1 = list.Skip(mid).FirstOrDefault();

                return v1;
            }
            else
            {
                int v1 = list.Skip(mid - 1).FirstOrDefault();
                int v2 = list.Skip(mid).FirstOrDefault();

                return (double)(v1 + v2) / (double)2;
            }
        }
    }
}
